<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>TestHTML</title>
</head>

<body>
    <p>与plant有关的前端请求</p>
    <div>
        <button id="exportDataButton">数据导出</button>
        <button id="runSimulationButton">仿真运行</button>
        <button id="importButton">数据导入</button>
    </div>
    <script>
        
        document.getElementById('exportDataButton').addEventListener('click', exportData);
        document.getElementById('runSimulationButton').addEventListener('click', runSimulation);
        document.getElementById('importButton').addEventListener('click', importData);

        async function exportData() {
       console.log('开始执行导出数据请求');
       const url = 'http://localhost:8000/api/plant_in/export';
       try {
           const response = await fetch(url, {
               method: 'GET',
           });
           if (response.ok) {
               console.log('数据导出成功');
           } else {
               console.error('数据导出失败');
           }
       } catch (error) {
           console.error('请求出错：', error);
       }
   }

        async function runSimulation() {
            const url = 'http://localhost:8000/api/plant_in/run';
            try {
                const response = await fetch(url, {
                    method: 'POST',
                });
                if (response.ok) {
                    console.log('模拟完成');
                } else {
                    console.error('模拟失败');
                }
            } catch (error) {
                console.error('请求出错：', error);
            }
        }


        async function importData() {
            const url = 'http://localhost:8000/api/plant_in/import';
            try {
                const response = await fetch(url, {
                    method: 'POST',
                });
                if (response.ok) {
                    console.log('数据导入成功');
                } else {
                    console.error('数据导入失败');
                }
            } catch (error) {
                console.error('请求出错：', error);
            }
        }
    </script>
</body>

</html>